package repository;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import domain.PropertyInc;

public class PropertyIncDAO extends BaseDAO {

	private static final long serialVersionUID = 8816251243030436810L;

	public PropertyIncDAO() throws SQLException {
		super();
	}

	@Override
	public ResultSet query(Object... params) {
		String sql = "SELECT * FROM 资产入库表  WHERE 物品ID=?;";
		ResultSet rs = null;
		
		try {
			PreparedStatement pst = con.prepareStatement(sql);			
			pst.setString(1, (String)params[0]);
			rs = pst.executeQuery();
		} catch (SQLException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return rs;
	}
	public ResultSet queryAll() {
		String sql = "SELECT * FROM 资产入库表;";
		ResultSet rs = null;
		
		try {
			PreparedStatement pst = con.prepareStatement(sql);			
			rs = pst.executeQuery();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rs;
	}

	@Override
	public int update(Object... params) {
		String sql = "UPDATE 资产入库表 SET 物品名称=?,物品价格=?,数量=? WHERE 物品ID=?;";
		int num = 0;
		try {
			PreparedStatement pst = con.prepareStatement(sql);
			PropertyInc acad = (PropertyInc)params[0];
			pst.setString(1, acad.getName());
			pst.setString(2, acad.getPrice());
			pst.setString(3, acad.getNumber());
			pst.setString(4, acad.getID());
			num = pst.executeUpdate();
		}catch(SQLException e) {
			e.printStackTrace();
		}
		return num;
	}

	@Override
	public int delete(Object... params) {
		String sql = "DELETE FROM 资产入库表 WHERE 物品ID=?;";
		int num = 0;
		try {
			PreparedStatement pst = con.prepareStatement(sql);
			pst.setString(1, (String)params[0]);
			num = pst.executeUpdate();
		}catch(SQLException e) {
			e.printStackTrace();
		}
		return num;
	}

	@Override
	public int insert(Object... params) {
		String sql = "INSERT INTO 资产入库表 (物品ID,物品名称,物品价格,数量) VALUES (?,?,?,?);";
		int num = 0;
		try {
			PreparedStatement pst = con.prepareStatement(sql);
			PropertyInc proin = (PropertyInc)params[0];
			pst.setString(1, proin.getID());
			pst.setString(2, proin.getName());
			pst.setString(3, proin.getPrice());
			pst.setString(4, proin.getNumber());
			num = pst.executeUpdate();
			System.out.println("数据库");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return num;
	}

}
